/*
 *    Copyright (c) 2018-2025, boss All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the boss developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: boss
 */
package com.hopes.bizz.risk.integral.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopes.bizz.risk.integral.entity.RiskIntegralExchangeAuditRecordEntity;
import com.hopes.bizz.risk.integral.dto.RiskIntegralExchangeAuditRecordExcelDTO;
import com.hopes.bizz.risk.integral.vo.RiskIntegralExchangeAuditRecordExcelVO;
import com.hopes.bizz.risk.integral.mapper.RiskIntegralExchangeAuditRecordMapper;
import com.hopes.bizz.risk.integral.service.RiskIntegralExchangeAuditRecordService;
import com.hopes.boss.common.entity.ValidateImportBO;
import com.hopes.boss.common.excel.vo.ErrorMessage;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 积分兑换审核记录
 *
 * @author pig
 * @date 2023-08-03 09:49:44
 */
@Service
public class RiskIntegralExchangeAuditRecordServiceImpl extends ServiceImpl<RiskIntegralExchangeAuditRecordMapper, RiskIntegralExchangeAuditRecordEntity> implements RiskIntegralExchangeAuditRecordService {

    @Override
    public ValidateImportBO<RiskIntegralExchangeAuditRecordExcelDTO> validateImport(List<RiskIntegralExchangeAuditRecordExcelDTO> excelDTOList) {
        ValidateImportBO<RiskIntegralExchangeAuditRecordExcelDTO> bo = new ValidateImportBO<>();
        List<ErrorMessage> errorMessageList = new ArrayList<>();
        List<RiskIntegralExchangeAuditRecordExcelDTO> saveList = new ArrayList<>(excelDTOList);
        int successNum = excelDTOList.size();
        int failedNum = 0;

        bo.setErrorMessages(errorMessageList);
        bo.setSaveList(saveList);
        bo.setSuccessNum(successNum);
        bo.setFailedNum(failedNum);
        return bo;
    }

    @Override
    public RiskIntegralExchangeAuditRecordEntity importDtoToEntity(RiskIntegralExchangeAuditRecordExcelDTO excelDto) {
        RiskIntegralExchangeAuditRecordEntity entity = new RiskIntegralExchangeAuditRecordEntity();
        BeanUtils.copyProperties(excelDto, entity);
        return entity;
    }

    @Override
    public RiskIntegralExchangeAuditRecordExcelVO exportEntityToVo(RiskIntegralExchangeAuditRecordEntity entity) {
        RiskIntegralExchangeAuditRecordExcelVO excelVO = new RiskIntegralExchangeAuditRecordExcelVO();
        BeanUtils.copyProperties(entity, excelVO);
        return excelVO;
    }

    @Override
    public void deleteByExchangeIdList(Collection<Long> exchangeIds) {
        if (CollectionUtils.isEmpty(exchangeIds)) {
            return;
        }
        List<RiskIntegralExchangeAuditRecordEntity> list = lambdaQuery().in(RiskIntegralExchangeAuditRecordEntity::getExchangeId, exchangeIds)
                .select(RiskIntegralExchangeAuditRecordEntity::getId)
                .list();

        List<Long> ids = list.stream().map(RiskIntegralExchangeAuditRecordEntity::getId).collect(Collectors.toList());
        this.removeByIds(ids);
    }
}